import publicForm from "@/components/public/el-forms.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
import TableData from "@/components/public/el-table-pagination"; //主页面列表
import CustomDialog from "@/components/materialQualityPage/constructionSiteLaboratoryManage/equipmentVerificationCalibration/index.vue";

import publicForm1 from "@/components/materialDataManage/fromCom.vue"; //弹框form

import {

    getEquipmentTestingInfoList, //列表页接口
    getFunctionRoomList, //功能室
} from "@/api/BackStage/materialQualityPage/request.js";

export default {
    props: [
        "dialogVisible",
        "currentRow",
    ],
    data() {
        return {
            visible: "",
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            materialInfo_config: formJs.materialInfo_config,
            // 列表
            getList: {
               
                page: 1, //当前页码
                pageSize: 20, //每页显示条数
                fId:""
            },
            loading: false,
            materialData: [], //种类数据
            tableData: [],
            title: null,
            isLock: false,
            dialogHeight: null,
            activeIndex: "1",
            btnShow: true,
            currentRow1: null,
            types: null,
            isShow:false
        };
    },
    components: {
        publicForm,
        CustomDialog,
        TableData,
        publicForm1
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                    this.getList.fId=this.currentDetail.fId
                        this.getDetail(this.getList)
                   
                }
            },
            immediate: true,
        },
    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.btnShow = true

        this.getHeight();
        // this.yj_searchForm(this.getList)

    },
    methods: {
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.5 + "px";
        },
        closeDialog1() {
            this.$emit("close1");
        },

        rowChange1(val) {
            this.getList.fId = val.fVarietyid;
            this.types = val
            // this.yj_searchForm(this.getList)
        },
        // 点击材料
        rowChange(val) {
            console.log(val);
            this.currentRow1 = val
            // this.dataFid = val.fId;
        },
        
        refreshList() { //刷新列表
            this.$nextTick(() => {
                this.getDetail(this.getList);
            })
        },
       
        closeDialog() {
            this.isShow = false;
        },
        // 点击查看
        yj_viewForm(row, label) {
            if (label == "计算管理方式") {
                this.statusNum = 7
                this.currentRow1 = row;
                this.isShow = true;
        
            }
        },
        // 获取列表数据
        getFunctionRoom(data) {
            var obj = {
                fCompanyid: data.fCompanyid, //左侧选中组织机构id
                page: 1, //当前页码
                typ: "",
                pageSize: 500, //每页显示条数
                
                keyWord: "", //上方查询条件样品名称
            }
            this.loading = true;
            var that = this;
            getFunctionRoomList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        this.searchObj[0].options=[{
                            label: "请选择",
                            value:""
                        }]
                        var dt=this.uniqueBy(res.data.pageInfo.list, 'functionRoom')
                        dt.map(item=>{
                            this.searchObj[0].options.push({
                                lable:item.functionRoom,
                                value:item.functionRoom
                            })
                        })
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },
        uniqueBy(array, key) {
            const seen = new Set();
            return array.filter((item) => {
              const keyValue = item[key];
              return seen.has(keyValue) ? false : seen.add(keyValue);
            });
          },
        // 获取列表数据
        getDetail(data) {
            var obj = {
               
                page: data.page, //当前页码
                pageSize: data.pageSize, //每页显示条数
                fId:data.fId
            }
            this.loading = true;
            var that = this;
            getEquipmentTestingInfoList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },



    },
};